#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<unistd.h>


int main()
{
  //_进程替换+等待
  pid_t id = fork();
  if(id == 0)
  {
     sleep(2);
     //child
    // execl("/usr/bin/ls","ls","-al",NULL);
     char* const argv[] = 
     {
       "ls",
       "-l",
       "-a",
       NULL
     };
     //execvp("ls",argv);
     //execv("/usr/bin/ls",argv);
     execl("./mypragma","mypragma",NULL);
     exit(1);
  }
  //father
  int status = 0;
  pid_t rid = waitpid(id,&status,0);//阻塞等待
  if(rid > 0)
  {
    if(WIFEXITED(status))
    {
       printf("wait success!,quit code = %d\n",WEXITSTATUS(status));
    }
    else printf("wait failed\n");
  }
  else 
  {
     printf("exit error!\n");
  }
  return 0;
}
